package com.liwei.appdata;

import com.liwei.beans.ClassRoom;
import com.liwei.beans.Stu;

import java.io.*;

public class MyApp {

    public static void main(String[] args) {
        ClassRoom classRoom = new ClassRoom(1, "io");
        Stu stu = new Stu(1000, "lw", 85,classRoom);
        String path = "D:\\aa.data";
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(path);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
            //如果对象所在类没有序列化，则操作对象流会报错
            //序列化是指把对象的内容【属性的结果数据进行流化】
            //java.io.NotSerializableException: com.bjpowernode.beans.Stu
            objectOutputStream.writeObject(stu);
            objectOutputStream.flush();
            objectOutputStream.close();
            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
